<?php
require('dbconnection.php');
db_connect();


$NUM_TABOO = 6;
$numImages = 2; //$_POST['current'];
$username = "bob"; //$_SESSION['uname'];



$query = "SELECT pic_number, pics.path  
	  FROM pics,descriptors 
	  where pics.number = descriptors.pic_number and 
	  	descriptors.user <> '$username'
          ORDER BY RAND() LIMIT 1";
$resultImages = mysql_query($query);





// We need a less sophisticated query
if(mysql_num_rows($resultImages)==0){
  $query = "SELECT pic_number, path  FROM pics ORDER BY RAND() LIMIT 1";
  $resultImages = mysql_query($query);
 }

if (!$resultImages)
  throw new Exception("There is no results for the Images query");



  
$images = mysql_fetch_row($resultImages);


if($numImages> $NUM_TABOO)
  $numImages = $NUM_TABOO;

//$query = "SELECT word from taboowords where path= '" .$images[0]."' limit ". $numImages;



$query = "select word 
	  from descriptors 
	  where pic_number = '$images[0]'
	  limit $numImages";


$resultTabooWords = mysql_query($query);



if (!$resultTabooWords)
  throw new Exception("There is no results for getting taboo words");



  
   

header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";

?>
<label>
<image> <?php echo $images[1]; ?></image>
    
<?php

				   // Number limited by the query
$numrows = 0;
while($words = mysql_fetch_row($resultTabooWords)){
  echo	"<tabooword>".$words[0]."</tabooword>\n";
  $numrows++;
 }


echo "</label>";
?>



